/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-11-01
 * Time: 18:49
 */
class Solution2 {
    public int[] searchRange(int[] nums, int target) {
        int[] result = new int[]{-1,-1};
        if(nums.length == 0 ){
            return result;
        }
        //左端点

        int left = 0 , right = nums.length-1 ,targetLeft = 0 , targetRight = 0;
        while(left < right){
            int mid = left + (right - left )/2;
            if(nums[mid] < target){
                left = mid + 1;
            }else{
                right = mid;
            }
        }
        targetLeft = left;
        left = 0 ; right = nums.length-1 ;

        //右端点
        while(left < right){
            int mid = left + (right-left+1)/2;
            if(nums[mid] > target){
                right = mid - 1;
            }else{
                left = mid;
            }
        }
        targetRight = right;


        if(nums[targetLeft] != target){
            return result;
        }else if(nums[targetLeft] == nums[targetRight]){
            result[0] = targetLeft;
            result[1] = targetRight;
            return result;
        }else{

        }

        return result;
    }
}
public class Test2 {
    public static void main(String[] args) {
        Solution2 test2 = new Solution2();
        //int[] array = {5,7,7,8,8,10};
        int[] array = {};

        test2.searchRange(array,6);
    }
}
